open Castling;;

module CharPG = ParserGenerator (CharToken);;
open CharPG;;

let rec primary = lazy !! (
	one_of ~name:"expr" [
		"", skip (element '(') >> expr >> skip (element ')');
		"call", primary >> position_of (element '(' >> expr >> element ')');
		"primary", position >> element '1']
) and right = lazy !! (
	one_of ~name:"expr" [
		"", primary;
		"pow", primary >> element '^' >> right]
) and term = lazy !! (
	one_of ~name:"expr" [
		"", right;
		"mul", term >> element '*' >> right;
		"div", term >> element '/' >> right]
) and expr = lazy !! (
	one_of ~name:"expr" [
		"", term;
		"add", expr >> element '+' >> term;
		"sub", expr >> element '-' >> term]
);;

debug := true;
runtime_debug := true;
ranged_position := true;;
generate expr;;
